package run.bottle.mail.model.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.http.HttpStatus;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;

@Data
@ToString
@EqualsAndHashCode
public class BaseResponse<T> {

    private Integer code;

    private String msg;

    private T data;

    public BaseResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static <T> BaseResponse<T> ok(@Nullable String msg, @Nullable T data) {
        return new BaseResponse<>(HttpStatus.OK.value(), msg, data);
    }

    public static <T> BaseResponse<T> ok(@Nullable String msg) {
        return ok(msg, null);
    }

    public static <T> BaseResponse<T> ok(@NonNull T data) {
        return new BaseResponse<>(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), data);
    }
}
